<template>
  <!-- 经销商列表 -->
  <div >
    <FilterTable
      ref="table"
      :dataSource="dataSource"
      :columns="columns"
      :isToperInfo="false"
      :isSelectColumn="false"
      :fetchapi="fetchParams"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      columnsRef="projectOperating_projram_commonForm_detail-dealer_01"
    ></FilterTable>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="经销商信息查询"
      :visible.sync="visibleDialog"
      width="800px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    ></BaseDialog>
  </div>
</template>

<script>
// import dealerDialog from './dealerDialog'
import { dictionary } from '@/utils/dictMixin';
//经销商窗口
import dealerMadal from '@/pages/cms-common/dealerdata';
import { getListByDealer } from '@/api/cms-api/projectOperating/program/distribution';
export default {
  mixins: [dictionary],
  components: {
    dealerMadal
  },
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formValue: {},
      editRow: {},
      initDealerData: {}, //经销商弹窗参数
      visibleDialog: false,
      initModal: {},
      recordId: '', //查看时，传递过来的数据ID
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null, //ipa 接口
      dataSource: []
    };
  },
  mounted() {
    //请求接口进行赋值，自己写吧
    if (this.value != null) {
      this.init();
    }
  },
  watch: {
    value: {
      handler(newV, oldV) {
        this.init();
      },
      deep: true
    }
  },
  methods: {
    async init() {
      //营销方案ID
      var id = this.value.rowData.projectProgramId;
      var projectOrgId = this.value.rowData.projectProgramOrgId; //营销方案事业部关系表ID
      // 更新接口需要的记录 ID
      this.recordId = id;
      if (id != '' || id != 'undefined') {
        let params = {
          projectProgramId: id, //方案ID
          projectOrgId: projectOrgId, //营销方案事业部关系表ID
          currentPage: 1,
          pageNum: 1,
          pageSize: 9999
        };
        //查询所辖经销商列表
        await getListByDealer(params).then(res => {
          this.dataSource = res.data.records;
          this.formValue = this.dataSource;
        });
      }
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
        { title: '经销商简称', dataIndex: 'dealerShortname', sorter: true },
        { title: '经销商全称', dataIndex: 'dealerName', sorter: true },
        {
          title: '是否查看',
          dataIndex: 'isView',
          sorter: true,
          render: props => {
            //编码转汉字
            let isView = props.row.isView;
            if (isView == null || typeof isView == 'undefined' || isView == '') isView = 10041002;
            return <span>{this.createDictText(isView, '1004')}</span>;
          }
        },
        { title: '首次查看人', dataIndex: 'firstViewPersonName', sorter: true },
        { title: '首次查看时间', dataIndex: 'firstViewTime', sorter: true, dateFormat: 'yyyy-MM-dd' }
      ];
    },
    openDialog() {
      this.initDealerData = {
        excludeBigCustomer: false, //是否查询大客户经销商，如果查询 true，不查询 false
        id: 1001
      };
      this.visibleDialog = true;
    }
  }
};
</script>
